import { reactive, readonly } from 'vue'
import { UserService } from '@/services/userService'
import { UserModel } from '@/models/userModel'
export const useUsersStore = () => {
    const state = reactive({
        users: []
    })
    const actions = {
        async loadUsers(uuid, token) {
            const response = await UserService.getUsers(uuid, token)
            console.log(response)
            state.users = response.data.map((user) => {
                return UserModel.fromApi(user)
            })
        },
        async addUser(user, uuid, token) {
            await UserService.addUser(user, uuid, token)
            actions.loadUsers(uuid, token)
        },
    }
    return {
        state: readonly(state),
        actions
    }
}